<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gravitee-instances-container">
  <div class="gravitee-instances-content">
    <div class="gravitee-instances-table-title"><ng-md-icon icon="info_outline"></ng-md-icon> Informations</div>
    <md-table-container>
      <table md-table>
        <tbody md-body>
        <tr md-row>
          <td md-cell><ng-md-icon icon="computer"></ng-md-icon></td>
          <td md-cell>Hostname</td>
          <td md-cell>{{$ctrl.instance.hostname}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="network_wifi"></ng-md-icon></td>
          <td md-cell>IP</td>
          <td md-cell>{{$ctrl.instance.ip}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="network_wifi"></ng-md-icon></td>
          <td md-cell>Port</td>
          <td md-cell>{{$ctrl.instance.port}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="traffic"></ng-md-icon></td>
          <td md-cell>State</td>
          <td md-cell ng-class="{'gravitee-instances-started':$ctrl.instance.state === 'started',
           'gravitee-instances-stopped':$ctrl.instance.state === 'stopped'}">{{$ctrl.instance.state}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="flag"></ng-md-icon></td>
          <td md-cell>Version</td>
          <td md-cell>{{$ctrl.instance.version}}</td>
        </tr>
        <tr md-row ng-if="$ctrl.instance.tags">
          <td md-cell><ng-md-icon icon="label"></ng-md-icon></td>
          <td md-cell>Sharding tags</td>
          <td md-cell>{{$ctrl.instance.tags}}</td>
        </tr>
        <tr md-row ng-if="$ctrl.instance.tenant">
          <td md-cell><ng-md-icon icon="shuffle"></ng-md-icon></td>
          <td md-cell>Tenant</td>
          <td md-cell>{{$ctrl.instance.tenant}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="timer"></ng-md-icon></td>
          <td md-cell>Started at</td>
          <td md-cell>{{$ctrl.instance.started_at | date:'medium'}}</td>
        </tr>
        <tr md-row>
          <td md-cell><ng-md-icon icon="favorite"></ng-md-icon></td>
          <td md-cell>Last heartbeat at</td>
          <td md-cell>{{$ctrl.instance.last_heartbeat_at | date:'medium'}}</td>
        </tr>
        <tr md-row ng-if="$ctrl.instance.stopped_at">
          <td md-cell><ng-md-icon icon="power_settings_new"></ng-md-icon></td>
          <td md-cell>Stopped at</td>
          <td md-cell>{{$ctrl.instance.stopped_at | date:'medium'}}</td>
        </tr>
        </tbody>
      </table>
    </md-table-container>
  </div>

  <div class="gravitee-instances-content">
    <div class="gravitee-instances-table-title"><ng-md-icon icon="extension"></ng-md-icon> Plugins</div>
    <md-table-container>
      <table md-table>
        <thead md-head md-order="order">
        <tr md-row>
          <th md-column></th>
          <th md-column md-desc md-order-by="id">ID</th>
          <th md-column md-order-by="name">Name</th>
          <th md-column md-order-by="version">Version</th>
        </tr>
        </thead>
        <tbody md-body>
        <tr md-row ng-repeat="plugin in $ctrl.instance.plugins | orderBy: order" title="{{plugin.name}}">
          <td md-cell ng-switch on="plugin.type">
            <ng-md-icon ng-switch-when="policy" icon="shuffle"></ng-md-icon>
            <ng-md-icon ng-switch-when="service" icon="layers"></ng-md-icon>
            <ng-md-icon ng-switch-when="repository" icon="folder_open"></ng-md-icon>
            <ng-md-icon ng-switch-when="reporter" icon="dashboard"></ng-md-icon>
            <ng-md-icon ng-switch-when="resource" icon="style"></ng-md-icon>
          </td>
          <td md-cell>{{plugin.id}}</td>
          <td md-cell>{{plugin.name}}</td>
          <td md-cell>{{plugin.version}}</td>
        </tr>
        </tbody>
      </table>
    </md-table-container>
  </div>

  <div class="gravitee-instances-content" ng-if="$ctrl.hasSystemProperties()">
    <div class="gravitee-instances-table-title" layout="row">
      <div flex="50">
        <ng-md-icon icon="assignment"></ng-md-icon> System properties
      </div>
      <div flex="50" layout="row">
        <input class="form-control gravitee-instances-table-search" type="text"
               ng-model="$ctrl.filterSystemProperty" ng-change="$ctrl.filter()"
               placeholder="Filter by name/value..." />
        <ng-md-icon icon="search"></ng-md-icon>
      </div>
    </div>
    <md-table-container>
      <table md-table>
        <thead md-head>
        <tr md-row>
          <th md-column>Name</th>
          <th md-column>Value</th>
        </tr>
        </thead>
        <tbody md-body>
        <tr md-row ng-repeat="(systemPropertyKey, systemPropertyValue) in $ctrl.instance.systemProperties">
          <td md-cell>{{systemPropertyKey}}</td>
          <td md-cell>{{systemPropertyValue}}</td>
        </tr>
        </tbody>
      </table>
    </md-table-container>
  </div>
</div>
